﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace console.demo.senior
{
    public class PriceTotaller
    {
        int countBooks = 0;
        decimal priceBooks = 0.0m;

        internal void AddBookToTotal(Book book)
        {
            countBooks++;
            priceBooks += book.Price;
        }

        internal decimal AveragePrice()
        {
            return priceBooks / countBooks;
        }

        static void PrintTitle(Book book)
        {
            Console.WriteLine(book.Title);
        }
        public static void testBook()
        {
            BookDB book = new BookDB();
            AddBooks(book);
            Console.WriteLine("paperback book titles");
            book.ProcessPaperbackBooks(PrintTitle);
            PriceTotaller priceTotallerprice = new PriceTotaller();
            book.ProcessPaperbackBooks(priceTotallerprice.AddBookToTotal);
            Console.WriteLine(priceTotallerprice.AveragePrice());
        }

        static void AddBooks(BookDB bookDB)
        {
            bookDB.Add("The C Programming Language", "Brian W. Kernighan and Dennis M. Ritchie", 19.95m, true);
            bookDB.Add("The Unicode Standard 2.0", "The Unicode Consortium", 39.95m, true);
            bookDB.Add("The MS-DOS Encyclopedia", "Ray Duncan", 129.95m, false);
            bookDB.Add("Dogbert's Clues for the Clueless", "Scott Adams", 12.00m, true);
        }
    }

}
